package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.Cabinet;
import com.share.device.service.ICabinetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/10/10 上午11:41
 */
@Tag(name = "充电宝柜机接口管理")
@RestController
@RequestMapping("/cabinet")
@RequiredArgsConstructor
public class CabinetController extends BaseController {

    private final ICabinetService cabinetService;


    @Operation(summary = "搜索未使用的柜机")
    @Log(title = "柜机")
    @GetMapping("/searchNoUseList/{keyword}")
    public AjaxResult searchNoUseList(@PathVariable String keyword){
        return success(cabinetService.searchNoUserList(keyword));
    }


    /**
     * 新增充电宝柜机
     *
     * @param cabinet
     * @return
     */
    @Operation(summary = "新增充电宝柜机")
    @RequiresPermissions("device:cabinet:add")
    @Log(title = "柜机",businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@RequestBody Cabinet cabinet) {
        return toAjax(cabinetService.saveCabinet(cabinet));
    }

    /**
     * 修改充电宝柜机
     *
     * @param cabinet
     * @return
     */
    @Operation(summary = "修改充电宝柜机")
    @RequiresPermissions("device:cabinet:edit")
    @Log(title = "柜机",businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult update(@RequestBody Cabinet cabinet) {
        return toAjax(cabinetService.updateCabinet(cabinet));
    }

    /**
     * 删除充电宝柜机
     *
     * @param ids
     * @return
     */
    @Operation(summary = "删除充电宝柜机")
    @RequiresPermissions("device:cabinet:remove")
    @Log(title = "柜机",businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(cabinetService.removeBatchByIds(ids));
    }

    /**
     * 获取充电宝柜机详细信息
     *
     * @param id
     * @return
     */
    @Operation(summary = "获取充电宝柜机详细信息")
    @RequiresPermissions("device:cabinet:query")
    @Log(title = "柜机")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(cabinetService.getById(id));
    }

    /**
     * 查询充电宝柜机列表
     *
     * @param cabinet
     * @return
     */
    @Operation(summary = "查询充电宝柜机列表")
    @RequiresPermissions("device:cabinet:list")
    @Log(title = "柜机")
    @GetMapping("/list")
    public TableDataInfo list(Cabinet cabinet) {
        startPage();
        List<Cabinet> list = cabinetService.selectCabinetList(cabinet);
        return getDataTable(list);
    }

    /**
     * 获取充电宝柜机全部详细信息
     *
     * @param id
     * @return
     */
    @Operation(summary = "获取充电宝柜机全部详细信息")
    @Log(title = "柜机")
    @GetMapping("/getAllInfo/{id}")
    public AjaxResult getAllInfo(@PathVariable Long id){
        return success(cabinetService.getAllInfo(id));
    }


}
